jQuery(document).ready(function() {
	$('#kit-search-more').on('click', function() {
		$('.kit-search-mored').toggle();
	});
	
	var col = [ 
	{
	checkbox: 'checkbox'
	},
	{
		title:'ID',
		field:'id',
		align: 'center',
		valign: 'middle',
		visible: false
	},
	{
		title:'购买日期',
		field:'id',
		align: 'center',
		valign: 'middle',
		visible: false
	},
	{
		title:'试听日期',
		field:'tryListenDate',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'英文名',
		field:'enName',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'上课账号',
		field:'zoomId',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'年龄',
		field:'age',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'老师名称',
		field:'teacherName',
		align: 'center',
		valign: 'middle',
	},
	{
		title:'课程',
		field:'course',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'试听类型',
		field:'tryListenType',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'状态',
		field:'tryListenState',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'录像',
		field:'recordVideo',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'跟进结果',
		field:'followUpResult',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'负责人',
		field:'fuzerenName',
		align: 'center',
		valign: 'middle',
		hidden:true
	},
	{
		title:'推荐人',
		field:'recommendName',
		align: 'center',
		valign: 'middle'
	},
/*	{
		title:'试听次数',
		field:'auditionCount',
		align: 'center',
		valign: 'middle'
	},*/
	{
		title:'备注',
		field:'comments',
		align: 'center',
		valign: 'middle'
	},
//	{
//		title: '操作',
//	    formatter: function (value, row, index) {
//		    var id = value;
//		    
//		    return '<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="beizhu()">备注</a>';
//	    } //自定义方法，添加操作按钮
//	
//	}
	];

	//------------------------------------------加载列表
	$('#_table').bootstrapTable({
		url:baseUrl+'/studentview',
		'method': "GET",
		locale: 'zh-CN',
		detailView: false,
		sidePagination: "server", //服务端处理分页
		striped: true,//隔行变色
		undefinedText: "",
		pagination: true,
		singleSelect: false,
		pageSize: pageList[0],
		cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pageNumber: 1,
		pageList: pageList,
		search: false, //不显示 搜索框
		uniqueId: "studentId", //每一行的唯一标识，一般为主键列
		showColumns: true, //不显示下拉框（选择显示的列）
		undefinedText: '',
		columns: col,
		queryParams: function(params) {
			return {
				pageNum: this.pageNumber,
				pageSize: this.pageSize,
				sortOrder: params.order
			}
		},
		
	});

})
var check = function() {

}

var doDelete = function() {
	var rows = $('#_table').bootstrapTable('getSelections');
	if(rows == [] || rows == null || rows.length == 0) {
		parent.layer.alert('请选择要编辑的数据！', {
			skin: 'layui-layer-molv', //样式类名
			closeBtn: 0,
			anim: 4,
			time: 2000
		});
		return;
	}
	if(rows.length != 1) {
		parent.layer.alert('请选择单条数据进行编辑！', {
			skin: 'layui-layer-molv', //样式类名
			closeBtn: 0,
			anim: 4,
			time: 1800
		});
		return;
	}
	$.ajax({
		type: "delete",
		url:baseUrl+ '/students/' + rows[0].studentId,
		async: true,
		success: function(data) {
			alert(data.msg);
			$('#_table').bootstrapTable('refresh');
		}
	});
}

var insert = function() {
	parent.layer.open({
		//				title: false,
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/TryListenEdit.html',
		btn: ['保存', '取消'],
		yes: function(index, layero) {
			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+ '/students',
				type: 'POST',
				data: data,
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
					$('#_table').bootstrapTable('refresh');
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}

var edit = function() {
	var rows = $('#_table').bootstrapTable('getSelections');
	if(rows == [] || rows == null || rows.length == 0) {
		parent.layer.alert('请选择要编辑的数据！', {
			skin: 'layui-layer-molv', //样式类名
			closeBtn: 0,
			anim: 4,
			time: 2000
		});
		return;
	}
	if(rows.length != 1) {
		parent.layer.alert('请选择单条数据进行编辑！', {
			skin: 'layui-layer-molv', //样式类名
			closeBtn: 0,
			anim: 4,
			time: 1800
		});
		return;
	}
	parent.layer.open({
		//				title: false,
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/TryListenEdit.html?studentId='+rows[0].studentId, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		btn: ['保存', '取消'],
		yes: function(index, layero) {
			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+'/students/'+rows[0].studentId,
				type: 'POST',
				data: data,
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
					$('#_table').bootstrapTable('refresh');
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
//			alert(index);
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}
